
//
//  HotPostTableViewController.m
//  DFForum
//
//  Created by lanou on 15/10/23.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "HotPostTableViewController.h"
#import "HotPostTableViewCell.h"
#import "HotPost.h"
#import "PKRequestManager.h"
#import "UIImageView+WebCache.h"

@interface HotPostTableViewController ()<UITabBarDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *dataSourceArray;
@end

@implementation HotPostTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    _dataSourceArray = [NSMutableArray array];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[HotPostTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self requestData];
}

- (void)requestData
{
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    parDic[@"page"] = @"1";
    parDic[@"userid"] = @"";
    parDic[@"vs"] = @"440";
    
    [PKRequestManager requestWithType:GET urlString:@"http://lib.wap.zol.com.cn/bbs/ios/getHotBook.php" parDic:parDic finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
        NSArray *listArray = dic[@"hotList"];
        for (NSDictionary *moDic in listArray) {
            HotPost *model = [[HotPost alloc] init];
            [model setValuesForKeysWithDictionary:moDic];
            [_dataSourceArray addObject:model];
            
        }
        [self.tableView reloadData];
    } error:^(NSError *error) {
        NSLog(@"页面请求失败");
    }];
}







- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return _dataSourceArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HotPostTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    HotPost *model = _dataSourceArray[indexPath.row];
    cell.timeLabel.text = model.title;
    [cell.authorImg sd_setImageWithURL:[NSURL URLWithString:model.photo]];
    cell.authorNameLabel.text = model.nickname;
    cell.replyLabel.text = model.reply;
    cell.replyTimeLabel.text = model.lastdate;
    cell.timeLabel.text = model.wdate;
    cell.typeName.text = model.bbsname;
    cell.supportLabel.text = model.favourNum;
    
    
    
    
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
